using MoonFramework.Scripts.View.UI;
using MoonFramework.Template;
using Tool;
using UnityEngine;
using UnityEngine.UI;

namespace UI.MenuUI
{
    [UIElement(false, "UI/UI_MainMenuWindow", 0)]
    public class UI_MainMenuWindow : BaseUIWindow
    {
        [SerializeField] private Button startButton, continueButton, exitButton;

        public override void Init()
        {
            base.Init();
            startButton.onClick.AddListener(NewGame);
            continueButton.onClick.AddListener(ContinueGame);
            exitButton.onClick.AddListener(ExitGame);

            startButton.BindMouseEffect();
            continueButton.BindMouseEffect();
            exitButton.BindMouseEffect();
        }

        public override void Close()
        {
            base.Close();
            startButton.RemoveMouseEffect();
            continueButton.RemoveMouseEffect();
            exitButton.RemoveMouseEffect();
        }

        public override void Show()
        {
            base.Show();
            //当前是否要显示 继续游戏按钮
            if (!ArchiveManager.Instance.HasArchive)
                continueButton.gameObject.SetActive(false);
        }

        private void NewGame()
        {
            //打开新游戏窗口
            UIManager.Instance.Show<UI_StartGameWindow>();
            Close();
        }

        private void ContinueGame()
        {
            //基于之前的存档进行游戏
            GameManger.Instance.UseCurArchive_EntryGame();
            Close();
        }

        private void ExitGame()
        {
            Application.Quit();
        }
    }
}